package com.wnxy.controller;


import com.wnxy.dto.ManagerDetail;
import com.wnxy.dto.NavDto;
import com.wnxy.dto.Result;
import com.wnxy.service.NavigationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author alice
 * @since 2021-11-12
 */
@RestController
@RequestMapping("/navigation")
public class NavigationController {
    @Autowired
private NavigationService navigationService;
    @GetMapping("/findNav")
    public Result findNav(){
        ManagerDetail managerDetail = (ManagerDetail) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        List<NavDto> navDtos=navigationService.findNavByManager(managerDetail.getManagerId());
        return Result.getInstance().setFlag(true)
                .setStatusCode(200)
                .setData(navDtos);
    }
    @GetMapping("/findByRole/{roleId}")
    public Result findByRole(@PathVariable("roleId") Integer roleId){
        List<Integer> nav = navigationService.findNavByRole(roleId);
        return Result.getInstance().setFlag(true)
                .setStatusCode(200)
                .setData(nav);
    }
}

